import {
  acceptOrderTypes,
  addressTypes,
  articleStatusOptions,
  dailyMenuTypeOpts,
  genderOptions,
  goodsStatusOpts,
  integralOpts,
  memberLabelOpts,
  printerTypeOpts,
  shopLabels,
  shopRoleOpts,
  shopTypes,
  skusOptions,
  statusOpt1,
  statusOpts,
  stockCalTypeOptions,
  supplierOpts,
  yesOrNoOpts,
  yesOrNoOpts_1
} from "@/utils/status";

type IFiledMap = {
  [key: string]: any;
};

type FT1 = {
  [key: string]: any;
};

function printerFields() {
  const res: FT1 = {
    shop_id: {title: "所属店铺", required: true, type: "select", options: []},
    type: {
      title: "打印机类型",
      required: true,
      type: "radio",
      options: printerTypeOpts(),
    },
    title: {title: "打印机名称", required: true},
    sn: {title: "终端编号", required: true},
    secret: {title: "终端识别码", required: true},
    status: {
      title: "状态",
      required: true,
      type: "radio",
      options: statusOpts(),
    },
  };

  return res;
}

//店铺
function supplierFields() {
  // step: number = 0
  const res: FT1 = [
    {
      supplier_id: {title: "所属商户", type: "select", range_key: 'title', required: true},
      title: {title: "店铺名称", required: true},
      name: {title: "店铺英文简称", required: true, placeholder: "用于生成商品或订单的前缀"},
      park_id: {title: "选择园区", type: "select", required: true, options: [], range_key: "title"},
      type: {title: "类型", type: "radio", required: true, options: shopTypes()},
      contact_name: {title: "负责人", required: true},
      /*app_name: {title: "店铺微信公众号", required: true},
      mch_id: {title: "微信支付商户号"},
      mch_secret: {title: "商户秘钥"},*/
      enable_profit_share: {title: "开启分账", required: true, type: "radio", options: yesOrNoOpts_1(),},
      distrute_rank: {title: "技术服务费比例", type: "number", unit: "%", relateKey: 'enable_profit_share', relateVal: 1},
      service_money: {title: "最低服务费", type: "number", relateKey: 'enable_profit_share', relateVal: 1},
      is_label: {title: "店铺标签", required: true, type: "radio", options: shopLabels(),},
      role_id: {title: "访问权限", required: true, type: "checkbox", options: shopRoleOpts(),},
      sort: {title: "排序", type: "number", append_tips: "越小越靠前"},
      status: {title: "状态", required: true, type: "radio", options: statusOpts(),},
    },
    {
      deliver_type: {title: "配送团队", type: "radio", options: ["第三方", '自营']},
      delivery_phone: {title: "配送员联系方式", type: "number", required: true},
      prepare_time: {title: "订单准备时间", required: true, type: "number", relateVal: 0, relateKey: 'type'}, // 第三方配送
      deliver_time: {title: "预计配送时间", required: true, type: "number", relateVal: 0, relateKey: 'type'}, // 第三方配送
      base_shipping_price: {title: "基础配送费", type: "base_price"},
      min_money: {title: "起送价", type: "number"},
      // ava_price: {title: "人均消费", type: "number"},
    },
    {
      thumb: {title: "店铺头像", required: true, type: "image", class: "el-form-full"},
      banner: {title: "店铺主图", required: true, type: "image", class: "el-form-full", append_tips: "用于店铺列表里的头图"},
      description: {title: "店铺简介", class: "el-form-full", type: "textarea"},
      notice: {title: "公告", class: "el-form-full", type: "textarea"},
      contact_phone: {title: "店铺客服电话", type: "number",},
      location: {title: "店铺所在地"},
      address: {title: "店铺详细地址"},
      store_time: {title: "营业时间", class: "el-form-full", type: "timerange", format: "HH:mm",},
      order_end_time: {title: "订单截止时间", class: "el-form-full", type: "textarea"},
      is_remark: {title: "接受用户备注", required: true, type: "radio", options: yesOrNoOpts_1(),},
      accept_order_type: {title: "接单方式", required: true, type: "radio", options: acceptOrderTypes(),},
      /* 0:下单减库存 1：付款减库存*/
      open_printer_task: {title: "打印任务", required: true, type: "radio", options: yesOrNoOpts_1()},
      stock_cal_type: {title: "库存计算方式", required: true, type: "radio", options: stockCalTypeOptions()},
      is_open: {title: "店铺状态", required: true, type: "radio", options: supplierOpts()},
    },
    {
      pictures: {title: "店铺环境图", required: true, type: "mutiImage", class: "el-form-full"},
      food_license: {title: "店铺食品安全档案", required: true, type: "image", class: "el-form-full"},
      business_license: {title: "营业执照", required: true, type: "image", class: "el-form-full"},
    }
  ]

  return res;
  // return res[step];
}

//商户
function shopFields() {

  const res: FT1 = {
    title: {title: "商户名称", required: true},
    contact_name: {title: "联系人"},
    contact_phone: {title: "联系方式", type: "number"},
    status: {
      title: "状态",
      required: true,
      type: "radio",
      options: statusOpts(),
    },
  };

  return res;
}

function productCategoryFields() {

  const res: FT1 = {
    shop_id: {title: "所属店铺", type: "select", required: true, range_key: "title", options: {}},
    title: {title: "分类名称", required: true},
    sort: {title: "排序", type: "number"},
    status: {title: "状态", required: true, type: "radio", options: statusOpts(), append_tips: "越小越靠前"},
  };

  return res;
}

function categoryFields() {

  const res: FT1 = {
    title: {title: "分类名称", required: true},
    /*shop_id: {
      title: "所属店铺",
      type: "select",
      required: true,
      range_key: "title",
      options: {}
    },*/
    sort: {title: "排序", type: "number"},
    status: {
      title: "状态",
      required: true,
      type: "radio",
      options: statusOpts(),
      append_tips: "越小越靠前"
    },
  };

  return res;
}

// 商品
function productFields(step: number = 0) {

  const res: FT1 = [
    {
      shop_id: {
        title: "所属店铺",
        type: "select",
        required: true,
        range_key: "title",
        class: "span2",
        options: {}
      },
      title: {title: "商品名称", required: true, max: 60},
      stall_id: {title: "所属档口", required: true, type: "select", range_key: "title", options: {}},
      category_id: {
        title: "所属分类",
        required: true,
        type: "select",
        range_key: "title",
        options: {}
      },
      thumb: {title: "商品预览图", required: true, type: "image"},
      // sn: {title: "商品编号"},
      min_buy: {title: "起售数量", type: "number", placeholder: "请输入，0为不限制"},
      limit_num: {title: "限购数量", type: "number", placeholder: "请输入，0为不限制"},
      is_single_seller: {title: "单点不送", type: "radio", options: yesOrNoOpts_1(), placeholder: "请输入，0为不限制"},
      content: {title: "商品描述", type: "textarea",},
      product_feed: {title: "商品主料",},
      product_taste: {title: "口味",},
      sort: {title: "排序", type: "number"},
      status: {
        title: "状态",
        required: true,
        type: "radio",
        options: goodsStatusOpts(),
        append_tips: "越小越靠前"
      },
    },
    {
      spec_type: {title: "规格类型", required: true, type: "radio", options: skusOptions(), append_tips: "商品实际购买金额"},
      skus: {title: "商品规格", relateKey: 'spec_type', relateVal: 20, options: skusOptions(), append_tips: "商品实际购买金额"},
      price: {title: "商品价格", required: true, type: "number",},
      cost_price: {title: "划线价", type: "number", append_tips: "仅用于展示"},
      stock: {title: "当前库存数量/件", required: true, type: "number", append_tips: "商品实际库存数量,为0时无法下单"},
      weight: {title: "商品重量/g", required: true, type: "number",},
      bag_price: {title: "打包费", required: true, type: "number",},
      seller_time: {title: "售卖时间", class: "el-form-full", type: "timerange", format: "HH:mm", append_tips: "不选为不限"},
    }
  ]

  return res;
}

//套餐
function comboFields(step: number = 0) {

  const res: FT1 = [
    {
      shop_id: {
        title: "所属店铺",
        type: "select",
        required: true,
        range_key: "title",
        class: "span2",
        options: {}
      },
      title: {title: "套餐名称", required: true},
      stall_id: {
        title: "所属档口",
        required: true,
        type: "select",
        range_key: "title",
        options: {}
      },
      category_id: {
        title: "所属分类",
        required: true,
        type: "select",
        range_key: "title",
        options: {}
      },
      thumb: {title: "套餐预览图", required: true, type: "image"},
      // sn: {title: "套餐编号"},
      min_buy: {title: "起售数量", type: "number", placeholder: "请输入，0为不限制"},
      limit_num: {title: "限购数量", type: "number", placeholder: "请输入，0为不限制"},
      content: {title: "套餐描述", type: "textarea",},
      product_feed: {title: "套餐主料",},
      product_taste: {title: "口味",},
      sort: {title: "排序", type: "number"},
      status: {
        title: "状态",
        required: true,
        type: "radio",
        options: goodsStatusOpts(),
        append_tips: "越小越靠前"
      },
    },
    {
      // spec_type: {title: "规格类型", required: true, type: "radio", options: skusOptions(), append_tips: "商品实际购买金额"},
      price: {title: "套餐价格", required: true, type: "number",},
      cost_price: {title: "划线价", type: "number", append_tips: "仅用于展示"},
      stock: {title: "当前库存数量/件", required: true, type: "number", append_tips: "商品实际库存数量,为0时无法下单"},
      weight: {title: "套餐重量/g", required: true, type: "number",},
      bag_price: {title: "打包费", required: true, type: "number",},
      seller_time: {title: "售卖时间", class: "el-form-full", type: "timerange", format: "HH:mm", append_tips: "不选为不限"},
      // stock_cal_type: {title: "库存计算方式", required: true, type: "radio", options: stockCalTypeOptions()},
      // select_amount: {title: "套餐选品总数量", type: 'number', append_tips: "商品实际购买金额"},
      skus: {title: "套餐规格", options: skusOptions(), append_tips: "商品实际购买金额"},
    }
  ]

  return res;
}


//档口
function stallFields() {
  const res: FT1 = {
    shop_id: {
      title: "所属商铺",
      required: true,
      type: "select",
      options: [],
    },
    title: {title: "档口名称", required: true},
    status: {
      title: "状态",
      required: true,
      type: "radio",
      options: statusOpts(),
    },
  };

  return res;
}

//园区
function parkFields() {

  const res: FT1 = {
    title: {title: "园区名称", required: true},
    status: {
      title: "状态",
      required: true,
      type: "radio",
      options: statusOpts(),
    },
  };

  return res;
}

//地址
function addressFields() {

  const res: FT1 = {
    title: {title: "名称", required: true},
    type: {title: "类型", type: "radio", required: true, options: addressTypes()},
    sort: {title: "排序", type: "number",},
    status: {
      title: "状态",
      required: true,
      type: "radio",
      options: statusOpts(),
    },
  };

  return res;
}

//积分
function memberIntegralFields() {
  const res: FT1 = {
    id: {title: "会员ID", required: true, disabled: true},
    integralType: {
      title: "修改积分",
      required: true,
      type: "radio",
      options: integralOpts(),
    },
    integral: {title: "积分数量", required: true},
  };

  return res;
}

/**
 * 会员字段
 */
function memberFields() {
  const res: FT1 = {
    username: {title: "会员昵称", required: true},
    mobile: {title: "手机号", type: "number", required: true},
    gender: {
      title: "性别",
      required: true,
      type: "radio",
      options: genderOptions(),
    },
    is_replace_order: {
      title: "代下单",
      required: true,
      type: "radio",
      options: yesOrNoOpts(),
    },
    is_deliver: {title: "配送员", required: true, type: "radio", options: yesOrNoOpts(),},
    // is_pick: {title: "分拣员", required: true, type: "radio", options: yesOrNoOpts_1(),},
    park_id: {
      title: "配送园区",
      required: true,
      type: "checkbox",
      relateKey: 'is_deliver',
      relateVal: 1,
      range_key: 'title',
      options: [],
    },
    type: {title: "会员标签", required: true, type: "checkbox", options: memberLabelOpts(),},
    summary: {title: "备注", type: "textarea"},
  };

  return res;
}

/**
 * 文章字段
 */
function articleFields() {
  const res: FT1 = {
    category_id: {title: "所属分类", required: true, type: "select", options: [], range_key: "title"},
    title: {title: "标题", required: true},
    // subtitle: {title: "副标题",},
    author_name: {title: "发布人",},
    sort: {title: "排序", type: "number"},
    // summary: {title: "简介", type: "textarea"},
    thumb: {title: "预览图", type: "image"},
    content: {title: "内容", type: "editor"},
    status: {title: "状态", required: true, type: "radio", options: articleStatusOptions(),},
  };

  return res;
}


/**
 * 文章字段
 */
function wemchFields() {

  const res: FT1 = {
    shop_id: {title: "所属店铺", required: true, type: "select", options: [], range_key: "title"},
    mch_id: {title: "商户编号", required: true},
    secret: {title: "商户秘钥", required: true},
    cert_path: {title: "证书pem地址", type: "image", required: true},
    key_path: {title: "证书key地址", type: "image", required: true},
    status: {title: "状态", required: true, type: "radio", options: statusOpts(),},
  };

  return res;
}

/**
 *每日菜单字段
 * 0:单店 1：食堂
 */
function dailyMenuFields(type = 0) {
  if (type == 1) {
    const res: FT1 = {
      date: {title: "菜单日期", required: true, type: "date", format: "YYYY-MM-DD",},
      shop_id: {title: "所属商铺", required: true, type: "select", options: [], hide: false},
      type: {title: "菜单类型", required: true, type: "select", isValue: true, options: dailyMenuTypeOpts(),},
      start_time: {
        title: "订餐开始时间",
        required: true,
        type: "datetime",
        format: "YYYY-MM-DD HH:mm:ss",
        tip: "开始时间大于结束时间，默认为第二天时间",
      },
      end_time: {
        title: "订餐截止时间",
        required: true,
        type: "datetime",
        format: "YYYY-MM-DD HH:mm:ss",
      },
      deliver_time: {title: "预计送达时间", required: true, type: "datetime", format: "YYYY-MM-DD HH:mm:ss",},
      // is_can_order: {title: "打烊后可预订点单", required: true, type: "radio", options: yesOrNoOpts_1()},
      status: {
        title: "状态",
        required: true,
        type: "radio",
        rangeKey: "title",
        options: statusOpt1(),
      },
    };
    return res;
  } else {
    const res: FT1 = {
      shop_id: {title: "所属商铺", required: true, type: "select", options: [], hide: false},
      expire_date: {title: "菜单有效期", required: true, type: "daterange", format: "YYYY-MM-DD",},
      is_can_order: {title: "打烊后可预订点单", required: true, type: "radio", options: yesOrNoOpts_1()},
      status: {
        title: "状态",
        required: true,
        type: "radio",
        rangeKey: "title",
        options: statusOpt1(),
      },
    };
    return res;
  }
}

export {
  printerFields,
  supplierFields,
  stallFields,
  parkFields,
  dailyMenuFields,
  memberIntegralFields,
  memberFields,
  shopFields,
  productCategoryFields,
  productFields,
  comboFields,
  categoryFields,
  articleFields,
  wemchFields,
  addressFields
};
